
# from .model import *

from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

model_name_zh_en = "hf-models/opus-mt-zh-en"
model_name_en_zh = "hf-models/opus-mt-en-zh"

tokenizer_zh_en = AutoTokenizer.from_pretrained(model_name_zh_en)
model_zh_en = AutoModelForSeq2SeqLM.from_pretrained(model_name_zh_en)

tokenizer_en_zh = AutoTokenizer.from_pretrained(model_name_en_zh)
model_en_zh = AutoModelForSeq2SeqLM.from_pretrained(model_name_en_zh)

# data = '''
# 在中国历史发展进程中，和合文化源远流长，蕴含着和以处众、和衷共济、政通人和、内和外顺等深刻的处世哲学和美好的社会理想，在中华文明中占有十分重要的位置，
# 是中华民族一系列和平实践、和平思想的灵魂。
# '''
# encoded = tokenizer_zh_en([data], return_tensors="pt")
# translation = model_zh_en.generate(**encoded)
# result = tokenizer_zh_en.batch_decode(translation, skip_special_tokens=True)[0]
# print(result)

# data = "hello every people!"
# encoded = tokenizer_en_zh([data], return_tensors="pt")
# translation = model_en_zh.generate(**encoded)
# result = tokenizer_en_zh.batch_decode(translation, skip_special_tokens=True)[0]
# print(result)

def fy(data,tokenizer,model):
    encoded = tokenizer([data], return_tensors="pt")
    translation = model.generate(**encoded)
    result = tokenizer.batch_decode(translation, skip_special_tokens=True)[0]
    return result

def fy_en_zh(data):
    return fy(data,tokenizer_en_zh,model_en_zh)

def fy_zh_en(data):
    return fy(data,tokenizer_zh_en,model_en_zh)




